2 + 2[1] 4
Why Learn to Code?
Julien Martin
University of Ottawa
April 1, 2024
this course (hopefully) will …
introduce you to using R ✔️
help your research become more robust and reproducible ✔️
this course (definitely) won’t …
teach you everything there is to know about R ❌
make you feel completely comfortable with R ❌
environment for statistical computing, graphics and programming
created by Ross Ihaka and Robert Gentleman (1996)
maintained by international R-core development team
many, people contribute to R and the wider R community
more information can be found at
https://www.r-project.com
download R from the CRAN website
https://cran.r-project.org/
high initial investment in time to learn R
unfamiliar command line environment
frustrating (and sometimes) inconsistent syntax
analysis and figures can take longer (initially!)
relatively steep learning curve
it’s not actually that hard, just unfamiliar
it’s free and platform independent
it’s the software of choice for many students, academics, industries and charities worldwide
highly flexible and extensive
encourages you think about your research
questions, data and analyses
it allows you to keep an exact and reproducible record of your analyses
transparent
other people1 can
reproduce your analysis
easily share your code (GitHub)
employability
opportunity to get involved
with a fantastic and supportive
community
#
R
IDE
you can install user contributed packages to increase versatility and power
there are packages for almost anything
install packages from CRAN, Bioconductor and GitHub
packages are easy to install in R
Write your own functions
function to calculate standard error
R is case sensitive A is not the same as a
commands are generally separated by a new line, but you can also use a ; (rare)
anything that follows the hash symbol # will be ignored by R. Use this to comment your code
a series of commands can be grouped using braces { }
write pretty code by following a code style guide
help() or ?or equivalently
help.search("plot") or ??plotDuckduckgo_it: Try online search You’ll be surprised how many other people have probably had the same problem and solved it.
Stack Overflow: There are thousands of questions relevant to R on Stack Overflow
Here are the most popular ones, ranked by vote.
make sure you include a reproducible example to get the most useful advice. A reproducible example is a minimal example that lets others who are trying to help you to see the error themselves.
use R regularly
learning R is not a memory test, you have your R scripts
you don’t need to know everything about R
don’t stare at code for hours.
there are many ways to tackle a particular problem
the time invested now will be more than payed back in the future.
Credit: I borrowed slides from Alex Douglas.
including the future you!↩︎